import axios from 'axios'

axios.defaults.withCredentials = true;

//过滤请求
axios.interceptors.request.use( function (config) {
  config.timeout = 600 * 1000 //请求响应时间
  return config
},   function (error) {
  return Promise.reject(error)
})

export default  function request(method, url, data) { //暴露 request 给我们好API 管理
  method = method.toLocaleLowerCase() //封装RESTful API的各种请求方式 以 post get delete为例
  if (method === 'post') {
    return  axios.post(url, data) //axios的post 默认转化为json格式
  } else if (method === 'get') {
    return  axios.get(url, {
      params: data
    })
  } else if (method === 'delete') {
    return  axios.delete(url, {
      params: data
    })
  }
}
